<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <title>个人中心</title>

</head>
<body>
<jsp:include page="/incloud/header.jsp"/>

<div class="d-flex align-items-stretch">
    <!-- Sidebar Navigation-->
    <jsp:include page="/incloud/sidebar.jsp"/>
    <!-- Sidebar Navigation end-->
    <div class="page-content">
        <div class="page-header">
            <div class="container-fluid">
                <h2 class="h5 no-margin-bottom">个人中心</h2>
            </div>
        </div>
        <section class="no-padding-bottom">
            <!-- Form Elements -->
            <div class="col-lg-12">
                <div class="block">
                    <div class="title"><strong>我的头像</strong></div>
                    <div class="avatar"><img src="${loginUser.pic}" id="pic" alt="加载中..." style="width: 150px;height: 150px"
                                             class="img-thumbnail rounded-circle"></div>
                    <div style="margin-top: 15px" class="text-left">
                        <!-- 真正的文件上传表单 -->
                        <input name="pic" type="file" id="picFile" style="display: none"/>
                    </div>
                    <div class="title">
                        <br>
                        <p class="h5"><strong>关注数：</strong><span>&nbsp;</span><span>&nbsp;</span><span>${focus}</span>
                        </p>
                        <br>
                        <p class="h5">
                            <strong>被看数：</strong><span>&nbsp;</span><span>&nbsp;</span><span>${loginUser.look}</span></p>
                        <br>
                    </div>
                    <div class="title"><strong>我的数据</strong></div>
                    <div class="block-body">
                        <form class="form-horizontal">
                            <div class="form-group row">
                                <label class="col-sm-3 form-control-label">真实姓名</label>
                                <div class="col-sm-9">
                                    <input type="text" id="realName" value="${loginUser.realName}" name="realName" class="form-control">
                                </div>
                            </div>
                            <div class="line"></div>
                            <div class="form-group row">
                                <label class="col-sm-3 form-control-label">所属部门</label>
                                <div class="col-sm-9">
                                    <select name="deptId"  id="deptId" class="selectpicker" data-live-search="true">
                                        <c:forEach items="${mapList}" var="dept" varStatus="status">
                                            <option value="${dept.id}" ${loginUser.deptId == dept.id?"selected":""}>${dept.name}</option>
                                        </c:forEach>
                                    </select>
                                </div>
                            </div>
                            <div class="line"></div>
                            <div class="form-group row">
                                <label class="col-sm-3 form-control-label">电话</label>
                                <div class="col-sm-9">
                                    <input type="text"  id="phone" value="${loginUser.phone}" name="phone" class="form-control">
                                </div>
                            </div>
                            <div class="line"></div>
                            <div class="form-group row">
                                <label class="col-sm-3 form-control-label">年龄</label>
                                <div class="col-sm-9">
                                    <input type="text"  id="age" placeholder="20" class="form-control" name="age" value="${loginUser.age}">
                                </div>
                            </div>
                            <div class="form-group row">
                                <label class="col-sm-3 form-control-label">性别 </label>
                                <div class="col-sm-9">

                                    <div class="i-checks">
                                        <input id="radioCustom1" ${loginUser.gender eq "1"?"checked":""} type="radio"
                                               value="1" name="gender" class="radio-template">
                                        <label for="radioCustom1">男</label>
                                        <span>&nbsp;</span><span>&nbsp;</span><span>&nbsp;</span>
                                        <input id="radioCustom2" ${loginUser.gender eq "0"?"checked":""} type="radio"
                                               value="0" name="gender" class="radio-template">
                                        <label for="radioCustom2">女</label>
                                    </div>
                                </div>


                            </div>
                            <div class="line"></div>
                            <div class="form-group row">
                                <label class="col-sm-3 form-control-label">注册时间</label>
                                <div class="col-sm-9">
                                    <input type="text" disabled="" placeholder="${user.registerTime}"
                                           class="form-control">
                                </div>
                            </div>
                            <div class="line"></div>
                            <div class="form-group row">
                                <label class="col-sm-3 form-control-label">登录时间</label>
                                <div class="col-sm-9">
                                    <input type="text" disabled="" placeholder="${user.loginTime}" class="form-control">
                                </div>
                            </div>
                            <div class="line"></div>

                            <div class="form-group row">
                                <label class="col-sm-3 form-control-label">是否私密 <br>
                                    <small class="text-primary">默认为否，可以不设置</small>
                                </label>
                                <div class="col-sm-9">
                                    <div class="i-checks">
                                        <input  id="checkboxCustom1" ${user.isSecret eq "0"?"checked":""} type="checkbox"
                                               value="" class="checkbox-template">
                                        <label for="checkboxCustom1">是否私密</label>
                                    </div>

                                </div>


                            </div>
                            <div class="line"></div>
                            <div class="text-center">
                                <input type="submit" class="btn btn-primary" value="保存">
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </section>

        <jsp:include page="/incloud/footer.jsp"/>
    </div>
</div>


</body>
</html>
<script>
    $(function () {
        $("#avatar").click(function () {
            location.href = "/user/detail?id=${loginUser.id}";
        })
        $("#pic").click(function () {
            $("#picFile").click();

        })
        $("#picFile").change(function () {
            var formdata = new FormData();
            formdata.append("pic",document.getElementById("picFile").files[0]);
            $.ajax({
                url:"/user/updatePic",
                type:"post",
                data:formdata,
                async:true,
                processData:false,
                contentType:false,
                success:function (data) {
                    $("#pic").attr("src",data);
                    $("#avatar img").attr("src",data);
                },
                error:function () {
                    //失败回调函数
                    layer.msg("服务繁忙，请稍后再试");
                }
            })
        })
        $("form").submit(function () {
            var realName = $("#realName").val();
            var deptId = $("#deptId").val();
            var phone = $("#phone").val();
            var age = $("#age").val();
            var gender = $("#radioCustom1").prop("checked") == true?1:0;
            var isSecret = $("#checkboxCustom1").prop("checked") == true?0:1;
            if(realName == ""){
                layer.msg("请填写真实姓名");
            }else if(phone == ""){
                layer.msg("请填写联系电话");
            }else if(age == ""){
                layer.msg("请填写年龄");
            }else{
                $.ajax({
                    url:"/user/updateInfo",
                    type:"post",
                    data:{
                        id:${loginUser.id},
                        realName:realName,
                        deptId:deptId,
                        gender:gender,
                        phone:phone,
                        age:age,
                        isSecret:isSecret
                    },
                    success:function () {
                        alert("修改信息成功！");
                        location.href="/user/detail?id=${loginUser.id}";
                    }
                })
            }

            return false;
        })
    })
</script>
